home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / dev / gui / titlebar_ic.lha / titlebar_ic / TBITest.c < prev    next >
C/C++ Source or Header  |  2001-01-20  |  8KB  |  225 lines

  1.  
  2.  
  3. /*  Titlebar.image test (19.1.2001)  */
  4. /*  Written for SAS/C                */
  5. /*  Compile: SC LINK TBITest         */
  6. /*  © 2001 Massimo Tantignone        */
  7. /*  e-mail: tanti@intercom.it        */
  8.  
  9.  
  10. #include "exec/types.h"
  11. #include "dos/dos.h"
  12. #include "intuition/intuition.h"
  13. #include "intuition/gadgetclass.h"
  14. #include "intuition/imageclass.h"
  15. #include "libraries/gadtools.h"
  16. #include "proto/intuition.h"
  17. #include "proto/exec.h"
  18.  
  19. #include <images/titlebar.h>
  20. #include <clib/titlebarimage_protos.h>
  21. #include <pragmas/titlebarimage_pragmas.h>
  22.  
  23.  
  24. /* The library base for the "titlebar.image" class library */
  25.  
  26. struct Library *TitlebarImageBase;
  27.  
  28.  
  29. ULONG main(void)
  30. {
  31.    /* The usual stuff */
  32.  
  33.    struct Screen *scr;
  34.    struct Window *win;
  35.    struct IntuiMessage *imsg;
  36.    struct DrawInfo *dri;
  37.    ULONG class, code, done = FALSE;
  38.    ULONG width = 640, height = 200;
  39.    struct Gadget *gad;
  40.    struct Image *i;
  41.  
  42.    /* Let's try to open the "titlebar.image" class library any way we can */
  43.  
  44.    TitlebarImageBase = OpenLibrary("titlebar.image",40L);
  45.  
  46.    if (!TitlebarImageBase)
  47.       TitlebarImageBase = OpenLibrary("Images/titlebar.image",40L);
  48.  
  49.    if (!TitlebarImageBase)
  50.       TitlebarImageBase = OpenLibrary("Classes/Images/titlebar.image",40L);
  51.  
  52.    /* Really not found? Then quit (and complain a bit) */
  53.  
  54.    if (!TitlebarImageBase) return (RETURN_FAIL);
  55.  
  56.    /* Lock the current default public screen */
  57.  
  58.    if (scr = LockPubScreen(NULL))
  59.    {
  60.       /* Inquire about the real screen size */
  61.  
  62.       width = scr->Width;
  63.       height = scr->Height;
  64.  
  65.       /* Get the screen's DrawInfo, it will be useful... */
  66.  
  67.       if (dri = GetScreenDrawInfo(scr))
  68.       {
  69.          /* Create an instance of the "tbiclass" image class */
  70.  
  71.          if (i = NewObject(NULL,"tbiclass",SYSIA_Which,ICONIFYIMAGE,
  72.                                            SYSIA_DrawInfo,dri,
  73.                                            TAG_END))
  74.          {
  75.             /* Attempt to create a gadget to go into the titlebar; */
  76.             /* of course it will use our new "tbiclass" image.     */
  77.  
  78.             /* Here we pass 2 to TBI_RELPOS() because there will be 2    */
  79.             /* gadgets at the right side of our new gadget in the        */
  80.             /* window titlebar: the zoom gadget and the depth gadget.    */
  81.             /* If we were to add another gadget to the left of this one, */
  82.             /* we would pass 3 for it, then 4 for a third, and so on.    */
  83.  
  84.             if (gad = NewObject(NULL,"buttongclass",
  85.                                      GA_RelRight,TBI_RELPOS(i,2),
  86.                                      GA_Top,0,
  87.                                      GA_Width,i->Width - 1,
  88.                                      GA_Height,i->Height,
  89.                                      GA_TopBorder,TRUE,
  90.                                      GA_Image,i,
  91.                                      GA_RelVerify,TRUE,
  92.                                      TAG_END))
  93.             {
  94.  
  95.                /* Open a window on the default public screen */
  96.  
  97.                if (win = OpenWindowTags(NULL,WA_Left,(width - 400) / 2,
  98.                                              WA_Top,(height - 250) / 2,
  99.                                              WA_Width,400,WA_Height,250,
  100.                                              WA_CloseGadget,TRUE,
  101.                                              WA_DepthGadget,TRUE,
  102.                                              WA_SizeGadget,TRUE,
  103.                                              WA_DragBar,TRUE,
  104.                                              WA_Gadgets,gad,
  105.                                              WA_SimpleRefresh,TRUE,
  106.                                              WA_Activate,TRUE,
  107.                                              WA_Title,"titlebar.image test",
  108.                                              WA_IDCMP,IDCMP_CLOSEWINDOW |
  109.                                                       IDCMP_REFRESHWINDOW |
  110.                                                       IDCMP_GADGETUP,
  111.                                              TAG_END))
  112.                {
  113.                   ULONG a, b, t = 0L;
  114.                   struct Image *v;
  115.  
  116.                   /* Show the various image types */
  117.  
  118.                   for (a = 0; a < 3; a++)
  119.                   {
  120.                      for (b = 0; b < 2; b++)
  121.                      {
  122.                         if (v = NewObject(NULL,"tbiclass",
  123.                                                SYSIA_Which,POPUPIMAGE + t++,
  124.                                                SYSIA_DrawInfo,dri,
  125.                                                TAG_END))
  126.                         {
  127.  
  128.                            DrawImageState(win->RPort,v,
  129.                                           50 + a * 100,50 + b * 100,
  130.                                           IDS_NORMAL,dri);
  131.  
  132.                            DrawImageState(win->RPort,v,
  133.                                           90 + a * 100,50 + b * 100,
  134.                                           IDS_SELECTED,dri);
  135.  
  136.                            DrawImageState(win->RPort,v,
  137.                                           50 + a * 100,90 + b * 100,
  138.                                           IDS_INACTIVENORMAL,dri);
  139.  
  140.                            DrawImageState(win->RPort,v,
  141.                                           90 + a * 100,90 + b * 100,
  142.                                           IDS_INACTIVESELECTED,dri);
  143.  
  144.                            WaitBlit();
  145.  
  146.                            DisposeObject(v);
  147.                         }
  148.                      }
  149.                   }
  150.  
  151.                   /* Put our iconify gadget to the front so it can be used */
  152.  
  153.                   /* We passed it also at window opening so that patches */
  154.                   /* centering window titles could compute the correct   */
  155.                   /* title position right from the start.                */
  156.  
  157.                   RemoveGadget(win,gad);
  158.                   AddGadget(win,gad,0);
  159.  
  160.                   /* Let's handle the events until the window gets closed */
  161.  
  162.                   while (!done)
  163.                   {
  164.                      Wait(1 << win->UserPort->mp_SigBit);
  165.  
  166.                      while (imsg = (struct IntuiMessage *)GetMsg(win->UserPort))
  167.                      {
  168.                         class = imsg->Class;
  169.                         code = imsg->Code;
  170.                         ReplyMsg((struct Message *)imsg);
  171.  
  172.                         if (class == IDCMP_CLOSEWINDOW) done = TRUE;
  173.  
  174.                         if (class == IDCMP_GADGETUP)
  175.                         {
  176.                            /* This was a message from our iconify gadget: */
  177.                            /* let's do something to show we received it.  */
  178.  
  179.                            DisplayBeep(NULL);
  180.                         }
  181.  
  182.                         if (class == IDCMP_REFRESHWINDOW)
  183.                         {
  184.                            BeginRefresh(win);
  185.                            EndRefresh(win,TRUE);
  186.                         }
  187.                      }
  188.                   }
  189.  
  190.                   /* Say good-bye to the window... */
  191.  
  192.                   CloseWindow(win);
  193.                }
  194.  
  195.                /* ... to the gadget... */
  196.  
  197.                DisposeObject(gad);
  198.             }
  199.  
  200.             /* ... and to the image */
  201.  
  202.             DisposeObject(i);
  203.          }
  204.  
  205.          /* Release the DrawInfo structure */
  206.  
  207.          FreeScreenDrawInfo(scr,dri);
  208.       }
  209.  
  210.       /* Finally unlock the screen */
  211.  
  212.       UnlockPubScreen(NULL,scr);
  213.    }
  214.  
  215.    /* Close the class library */
  216.  
  217.    CloseLibrary(TitlebarImageBase);
  218.  
  219.    /* We did our job, now let's go home :-) */
  220.  
  221.    return (RETURN_OK);
  222. }
  223.  
  224.  
  225.